package com.groupbuying.currency.producer.controller;

import com.groupbuying.currency.producer.context.FilterContextHandler;
import com.groupbuying.currency.producer.domain.CurrencyCustomerLogDO;
import com.groupbuying.currency.producer.dto.CurrencyCustomerLogDTO;
import com.groupbuying.currency.producer.service.CurrencyCustomerLogService;
import com.groupbuying.currency.producer.utils.PageUtils;
import com.groupbuying.currency.producer.utils.Query;
import com.groupbuying.currency.producer.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 积分日志表
 * 
 * @author ywxd
 * @email yuwenxiaodong@126.com
 * @date 2019-04-15 17:21:02
 */
 
@Controller
@RequestMapping("/currency/currencyCustomerLog")
public class CurrencyCustomerLogController {
	public static final Logger logger = LoggerFactory.getLogger(CurrencyCustomerLogController.class);

	@Autowired
	private CurrencyCustomerLogService currencyCustomerLogService;

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<CurrencyCustomerLogDO> currencyCustomerLogList = currencyCustomerLogService.list(query);
		int total = currencyCustomerLogService.count(query);
		PageUtils pageUtils = new PageUtils(currencyCustomerLogList, total);
		return pageUtils;
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( CurrencyCustomerLogDO currencyCustomerLog){
		if(currencyCustomerLogService.save(currencyCustomerLog)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( CurrencyCustomerLogDO currencyCustomerLog){
		currencyCustomerLogService.update(currencyCustomerLog);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( String logId){
		if(currencyCustomerLogService.remove(logId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") String[] logIds){
		currencyCustomerLogService.batchRemove(logIds);
		return R.ok();
	}

	@GetMapping("/details")
	@ResponseBody
	public PageUtils details(@RequestParam Map<String, Object> params){
		String consumerId = FilterContextHandler.getUserID();
		params.put("consumerId",consumerId);
		logger.info("details：{}",params.toString());
		//查询列表数据
		Query query = new Query(params);
		List<CurrencyCustomerLogDTO > currencyCustomerLogList = currencyCustomerLogService.details(query);
		logger.error("返回得到的currencyCustomerLogList："+currencyCustomerLogList.toString()+"----"+currencyCustomerLogList.size());
		int total = currencyCustomerLogService.detailsCount(consumerId);
		logger.error("返回得到的total："+total);
		PageUtils pageUtils = new PageUtils(currencyCustomerLogList, total);
		logger.error("返回得到的pageUtils："+pageUtils.getRows()+"-------"+pageUtils.getTotal());
		return pageUtils;
	}
}
